package com.kg.fiber.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ivan.toolkit.common.Aniout;
import com.ivan.toolkit.common.Anival;
import com.kg.fiber.service.Simulator;

@Controller
@RequestMapping("/simu")
@ResponseBody
public class SimuController {
	
	@Autowired
	private Simulator simulator;
		
	@RequestMapping(value = "/get.do")
	public Anival getSimulator() {
		Anival av = new Anival();
		av.put("number", simulator.getSingleNumber());
		av.put("interval", simulator.getSingleInterval());
		av.put("base", simulator.getBase());
		av.put("scope", simulator.getScope());
		av.put("step", simulator.getStep());
		av.put("enabled", simulator.isEnabled());
		return av;
	}
	
	@RequestMapping(value = "/set.do")
	public Aniout setSimulator(int number, int interval, double base, double scope, double step, boolean enabled) {
		number = Math.max(number, 1000);
		interval = Math.max(interval, 10);
		simulator.setEnabled(false);
		simulator.setSingleNumber(number);
		simulator.setSingleInterval(interval);
		simulator.setBase(base);
		simulator.setScope(scope);
		simulator.setStep(step);
		simulator.setEnabled(enabled);
		return Aniout.success();
	}
	
	@RequestMapping(value = "/upBase.do")
	public Aniout upSimulatorBase() {
		simulator.upBase();
		return Aniout.success();
	}
	
	@RequestMapping(value = "/downBase.do")
	public Aniout downSimulatorBase() {
		simulator.downBase();
		return Aniout.success();
	}
	
}
